package com.dc.refactoring._5_简化函数调用._14_ReplaceExceptionWithTest;

import com.google.common.base.Preconditions;
import com.google.common.base.Strings;

import java.util.Objects;

public class AppService {

    /**
     * 保存APP 信息，ID和NAME 不能为空
     * @param app
     * @return
     */
    public boolean insertApp1(App app) {
        try {

            // 调用DAO层，保存 app 业务逻辑,当前Name或ID 为空时，保存会报错

            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }



    public boolean insertApp2(App app) {
        try {
            // 提前校验数据
            Preconditions.checkArgument(Objects.nonNull(app));
            Preconditions.checkArgument(Objects.nonNull(app.getId()));
            Preconditions.checkArgument(!Strings.isNullOrEmpty(app.getName()));

            // 调用DAO层，保存 app 业务逻辑

            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

}

